#pragma once
#include <iostream>
#include <string>
#include <functional>
#include <unordered_map>

#include"Tcp_Server.hpp"
#include"HttpServer.hpp"


void Login(HttpRequest &req, HttpResponse &resp)
{
    LOG(LogLevel::DEBUG) << "进入登录模块" << req.Path() << ", " << req.Args();
    string req_args=req.Args();

    // 3. 登录成功
    std::string body = req.GetContent("www/success.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length", std::to_string(body.size()));
    resp.SetHeader("Content-Type", "text/html");
    resp.SetHeader("Set-Cookie", "usename=zhangsan&passwd=11111111");
    resp.SetBody(body);

}


void Register(HttpRequest &req, HttpResponse &resp)
{
    // 根据req，动态构建resp
    LOG(LogLevel::DEBUG) << "进入注册模块" << req.Path() << ", " << req.Args();
}

void Search(HttpRequest &req, HttpResponse &resp)
{
    // 根据req，动态构建resp
    LOG(LogLevel::DEBUG) << "进入搜索模块" << req.Path() << ", " << req.Args();
}

void Test(HttpRequest &req, HttpResponse &resp)
{
    // 根据req，动态构建resp
    LOG(LogLevel::DEBUG) << "进入测试模块" << req.Path() << ", " << req.Args();
}


int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    auto httpserver = std::make_unique<HttpServer>(std::stoi(argv[1]));
    // 要让服务器具有登录功能
    httpserver->Resgiter("/login", Login); // restful风格的网络请求接口
    httpserver->Resgiter("/register", Register);
    httpserver->Resgiter("/search", Search);
    httpserver->Resgiter("/test", Test);
    httpserver->Start();
    return 0;
}